<?php
	check_login();
	$a = getAction();

	switch($a) {
		case 'index':
			$sql = " select *  from " . table('flash') . " where status <> '-1' order by seq_no asc";
			$url="admin.php?m=flash";

			$rscount=$db->getOne("select count(1) from ($sql) temp");
			$pagesize=20;
			$page=max(1,intval($_GET['page']));
			$start=($page-1)*$pagesize;
			$sql.=" limit $start,$pagesize";
			
			$list = $db->getAll($sql);
			
			for($i= 0; $i < count($list); $i++) {
				if($list[$i]["type"] == "1") {
					$list[$i]["type_name"] = "充值页面";
				}
			}

			$smarty->assign("pagelist",multipage($rscount,$pagesize,$page,$url));
			$smarty->assign("list", $list);

			$smarty->display("flash.html");
			break;	
		case "add":
			$id = get_post("id");
				
			if($_POST) {
				$formData = $_POST["formData"];
				$nowTime = getNowTime();
			
				if($id) {
					$formData["id"] = $id;
					$formData["update_time"] = $nowTime;
					$db->update("flash", $formData, " and id = $id ");
				} else {
					$formData["status"] = STATUS::INVALID;
					$formData["insert_time"] = $nowTime;
					$formData["update_time"] = $nowTime;
					$db->insert("flash", $formData);
				}

				gourl("admin.php?m=flash");
			} else {
				if($id) {
					$formData = $db->getRow("select * from " . table('flash') . " where id = $id ");
					$smarty->assign("formData", $formData);
				}

				$smarty->display("flash_add.html");
			}
					
			break;	
		case "show":
			$id = intval($_GET['id']);
			$status = trim($_GET['t']);
			if($id) {
				$db->query("update " . table("flash") . " set status = '$status' where id = '$id'");
			}
			break;
					
		case "del":
			$id = $_GET["id"];
			$sql = "delete from " . table("flash") . "where id = '$id'";
			$db->query($sql);
			
			gourl();
			break;	
	}